home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / C / xid.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  6.0 KB  |  267 lines

  1. /* ----------------------------------------------------------------
  2.  * xid.c --
  3.  *    POSTGRES transaction identifier code.
  4.  *
  5.  * XXX WARNING
  6.  *    Much of this file will change when we change our representation
  7.  *    of transaction ids -cim 3/23/90
  8.  *
  9.  * It is time to make the switch from 5 byte to 4 byte transaction ids
  10.  * This file was totally reworked. -mer 5/22/92
  11.  * ----------------------------------------------------------------
  12.  */
  13.  
  14. #include "tmp/postgres.h"
  15.  
  16. RcsId("$Header: /private/postgres/src/lib/C/RCS/xid.c,v 1.4 1992/05/28 23:07:42 mer Exp $");
  17.  
  18. #include "utils/palloc.h"
  19. #include "utils/log.h"
  20. #include "utils/memutils.h"
  21.  
  22. /* ----------------------------------------------------------------
  23.  *    transaction system constants
  24.  *
  25.  *    read the comments for GetNewTransactionId in order to
  26.  *      understand the initial values for AmiTransactionId and
  27.  *      FirstTransactionId. -cim 3/23/90
  28.  * ----------------------------------------------------------------
  29.  */
  30.  
  31. extern TransactionId NullTransactionId;
  32. extern TransactionId DisabledTransactionId;
  33. extern TransactionId AmiTransactionId;
  34. extern TransactionId FirstTransactionId;
  35.  
  36.  
  37. /* ----------------------------------------------------------------
  38.  *     TransactionIdIsValid
  39.  *
  40.  *    Macro-ize me.
  41.  * ----------------------------------------------------------------
  42.  */
  43.  
  44. bool
  45. TransactionIdIsValid(transactionId)
  46.     TransactionId    transactionId;
  47. {
  48.     return ((bool) (transactionId != NullTransactionId) );
  49. }
  50.  
  51. /* ----------------------------------------------------------------
  52.  *    StringFormTransactionId
  53.  *
  54.  *    Not sure if this is still needed -mer 5/22/92
  55.  * ----------------------------------------------------------------
  56.  */
  57.  
  58. TransactionId
  59. StringFormTransactionId(representation)
  60.     String    representation;
  61. {
  62.     return (atol(representation));
  63. }
  64.  
  65. /* ----------------------------------------------------------------
  66.  *    TransactionIdFormString
  67.  * ----------------------------------------------------------------
  68.  */
  69.  
  70. String
  71. TransactionIdFormString(transactionId)
  72.     TransactionId    transactionId;
  73. {
  74.     String            representation;
  75.  
  76.     /* maximum 32 bit unsigned integer representation takes 10 chars */
  77.     representation = palloc(11);
  78.  
  79.     (void)sprintf(representation, "%lu", transactionId);
  80.  
  81.     return (representation);
  82. }
  83.  
  84. /* ----------------------------------------------------------------
  85.  *    PointerStoreInvalidTransactionId
  86.  *
  87.  *    Maybe do away with Pointer types in these routines.
  88.  *      Macro-ize this one.
  89.  * ----------------------------------------------------------------
  90.  */
  91.  
  92. void
  93. PointerStoreInvalidTransactionId(destination)
  94.     Pointer        destination;
  95. {
  96.     * (TransactionId *) destination = NullTransactionId;
  97. }
  98.  
  99. /* ----------------------------------------------------------------
  100.  *    TransactionIdStore
  101.  *
  102.  *      Macro-ize this one.
  103.  * ----------------------------------------------------------------
  104.  */
  105.  
  106. void
  107. TransactionIdStore(transactionId, destination)
  108.     TransactionId    transactionId;
  109.     TransactionId    *destination;
  110. {
  111.     *destination = transactionId;
  112. }
  113.  
  114. /* ----------------------------------------------------------------
  115.  *    TransactionIdEquals
  116.  * ----------------------------------------------------------------
  117.  */
  118.  
  119. bool
  120. TransactionIdEquals(id1, id2)
  121.     TransactionId    id1;
  122.     TransactionId    id2;
  123. {
  124.     return ((bool) (id1 == id2));
  125. }
  126.  
  127. /* ----------------------------------------------------------------
  128.  *    TransactionIdIsLessThan
  129.  * ----------------------------------------------------------------
  130.  */
  131.  
  132. bool
  133. TransactionIdIsLessThan(id1, id2)
  134.     TransactionId    id1;
  135.     TransactionId    id2;
  136. {
  137.     return ((bool)(id1 < id2));
  138. }
  139.  
  140. /* ----------------------------------------------------------------
  141.  *    xidgt
  142.  * ----------------------------------------------------------------
  143.  */
  144.  
  145. /*
  146.  *    xidgt        - returns 1, iff xid1 > xid2
  147.  *                  0  else;
  148.  */
  149. bool
  150. xidgt(xid1, xid2)
  151. XID     xid1, xid2;
  152. {
  153.  
  154.     return( (bool) (xid1 > xid2) );
  155. }
  156.  
  157. /* ----------------------------------------------------------------
  158.  *    xidge
  159.  * ----------------------------------------------------------------
  160.  */
  161.  
  162. /*
  163.  *    xidge        - returns 1, iff xid1 >= xid2
  164.  *                  0  else;
  165.  */
  166. bool
  167. xidge(xid1, xid2)
  168. XID     xid1, xid2;
  169. {
  170.     return( (bool) (xid1 >= xid2) );
  171. }
  172.  
  173.  
  174. /* ----------------------------------------------------------------
  175.  *    xidle
  176.  * ----------------------------------------------------------------
  177.  */
  178.  
  179. /*
  180.  *    xidle        - returns 1, iff xid1 <= xid2
  181.  *                  0  else;
  182.  */
  183. bool
  184. xidle(xid1, xid2)
  185. XID     xid1, xid2;
  186. {
  187.     return((bool) (xid1 <= xid2) );
  188. }
  189.  
  190.  
  191. /* ----------------------------------------------------------------
  192.  *    xideq
  193.  * ----------------------------------------------------------------
  194.  */
  195.  
  196. /*
  197.  *    xideq        - returns 1, iff xid1 == xid2
  198.  *                  0  else;
  199.  */
  200. bool
  201. xideq(xid1, xid2)
  202. XID     xid1, xid2;
  203. {
  204.     return( (bool) (xid1 == xid2) );
  205. }
  206.  
  207.  
  208.  
  209. /* ----------------------------------------------------------------
  210.  *    xidmi
  211.  * ----------------------------------------------------------------
  212.  */
  213.  
  214. /*    xidmi        - returns the distance xid1 - xid2
  215.  *
  216.  */
  217. int
  218. xidmi(xid1, xid2)
  219. XID    xid1, xid2;
  220. {    /* computes the 'distance' between xid1 and xid2:
  221.      * if there was no xidj generated between the generation of
  222.      * xid1 and xid2, then the distance (xid1 - xid2) has to be 1 (!!!) */
  223. }
  224.  
  225. /* ----------------------------------------------------------------
  226.  *    TransactionIdIncrement
  227.  * ----------------------------------------------------------------
  228.  */
  229.  
  230. void
  231. TransactionIdIncrement(transactionId)
  232.     TransactionId    *transactionId;
  233. {
  234.  
  235.     (*transactionId)++;
  236.     if (*transactionId == DisabledTransactionId)
  237.         elog(FATAL, "TransactionIdIncrement: exhausted XID's");
  238.     return;
  239. }
  240.  
  241. /* ----------------------------------------------------------------
  242.  *    TransactionIdAdd
  243.  * ----------------------------------------------------------------
  244.  */
  245. void
  246. TransactionIdAdd(xid, value)    
  247.     TransactionId *xid;
  248.     int          value;
  249. {
  250.     *xid += value;
  251.     return;
  252. }
  253.  
  254. /* ----------------------------------------------------------------
  255.  *    TransactionIdGetApproximateTime
  256.  * ----------------------------------------------------------------
  257.  */
  258.  
  259. Time
  260. TransactionIdGetApproximateTime(transactionId)
  261.     TransactionId    *transactionId;
  262. {
  263.     Time temp;
  264.     temp = (*transactionId) / TransactionsPerSecondAdjustment;
  265.     return(temp);
  266. }
  267.